using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace JwtBearerAuthor.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    public class WeatherForecastController : ControllerBase
    {
        private static readonly string[] Summaries = new[]
        {
            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        };

        private readonly ILogger<WeatherForecastController> _logger;

        public WeatherForecastController(ILogger<WeatherForecastController> logger)
        {
            _logger = logger;
        }

        [HttpGet]
        [Route("GetWithNoAuthorize")]
        public string GetWithNoAuthorze()
        {
            return "Hello";
        }

        [Authorize(Roles = "admin")]
        [HttpGet]
        [Route("GetWithRole_admin")]
        public string GetWithRole_admin()
        {
            return "Hello";
        }

        // admin或user角色
        [Authorize(Roles = "admin,user")]
        [Route("GetWithRole_adminORuser")]
        [HttpGet]
        public string GetWithRole_adminORuser()
        {
            return "Hello";
        }

        // admin且user角色
        [Authorize(Roles = "admin")]
        [Authorize(Roles = "user")]
        [Route("GetWithRole_adminANDuser")]
        [HttpGet]
        public string GetWithRole_adminANDuser()
        {
            return "Hello";
        }

        // 授权 - 基于策略
        [Authorize(Policy = "policy1")]
        [Route("GetWithPolicy_policy1")]
        [HttpGet]
        public string GetWithPolicy_policy1()
        {
            return "Hello";
        }
    }
}